﻿using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.Linq;
using System.Text;
using RecordTime.Infrastructure.Mapping;
using RecordTime.Models;
using RecordTime.Repository;

namespace RecordTime.Infrastructure.Services
{
    [Export(typeof(IProjectManagementService))]
    public class ProjectManagementService : IProjectManagementService
    {
        [Import]
        public IMappingService MappingService { get; set; }

        [Import]
        public IUnitOfWork UnitOfWork { get; set; }

        #region Implementation of IProjectManagementService

        public IEnumerable<Task> GetTasks()
        {
            return MappingService.GetAll(UnitOfWork.TaskRepository.GetAll());
        }

        public void CreateTask(Task task)
        {
            using (UnitOfWork)
            {
                UnitOfWork.TaskRepository.Insert(MappingService.GetEntity(task));
                UnitOfWork.Save();
            }
        }

        #endregion
    }
}
